const initialState = {
    data:[]
}

export default (state = initialState, { type, payload }) => {
    let newState = JSON.parse(JSON.stringify(state))
  switch (type) {

    case "ADD_TODULIST":
        newState.data.push(payload)
        return newState
    
    case "DEL_TODULIST":
        newState.data.forEach((item,index)=>{
            if(item.id === payload){
                newState.data.splice(index,1)
            }
        })
        return newState
    case "EDIT_TODULIST":
        newState.data.forEach((item,index)=>{
            if(item.id === payload.id){
                newState.data[index] = {
                    ...payload
                }
                // {
                //     ...payload
                // }
                // item.value = payload.value
                // item.date = payload.date
            }
        })
        return newState

  default:
    return newState
  }
}
